//Please declare the floatingCombos array in your own jsp page
//e.g. var floatingCombos = new Array("myCombo1","myCombo2");
var activeSelectedFieldID=null;
var activeSelectedFieldValue=null;
var activeFloatingCombo=null;
var activeFloatingBox=null;

function hideAllFloatingCombo(){
  alert(floatingCombos);
  if(floatingCombos){
    for(i=0;floatingCombos.length;i++){
      hideFloatingCombo(floatingCombos[i]);
    }
  }
}

function hideFloatingCombo(name){
  combo = document.getElementById(name);
  if(combo!=null)
      combo.style.visibility = 'hidden';
}

function triggerFloatingCombo(locator,fieldID,fieldName,activeFloatingComboName,activeFloatingBoxName,isClick){
  //display on key down

  var keyCode = (window.event?window.event.keyCode:null);
  if(isClick || keyCode==38 || keyCode==40 ){  
    hideFloatingCombo(activeFloatingCombo);
    var divLayer = document.getElementById(locator);
    var combo;
    var currentInputKeyBox = document.getElementById(fieldID);
    var currentInputValueBox = document.getElementById(fieldName);
    activeSelectedFieldID=fieldID;
    activeSelectedFieldValue=fieldName;
    combo = document.getElementById(activeFloatingComboName);
    combo.style.top=divLayer.offsetTop+22;
    combo.style.left=divLayer.offsetLeft+1;
    combo.style.visibility = 'visible';
    activeFloatingBox = activeFloatingBoxName;

    var selectionBox = document.getElementById(activeFloatingBoxName);
    selectionBox.style.height = "auto";
    var activeSelectFieldIDValue = document.getElementById(activeSelectedFieldID).value;
    for(i=0;i<selectionBox.options.length;i++){
      if(selectionBox[i].text==activeSelectFieldIDValue){
        selectionBox[i].selected=true;
        break;
      }
    }
    selectionBox.focus();
  }
}


function fireSelection(event,isClick,postProcessFunctionName){
  //alert(window.event.keyCode);
  var keyCode = (window.event?window.event.keyCode:null);
  if(keyCode==27 || keyCode==9){
    hideFloatingCombo(activeFloatingCombo);
  }else if(isClick || keyCode==13){
    var currentInputKeyBox = document.getElementById(activeSelectedFieldID);
    var currentInputValueBox = document.getElementById(activeSelectedFieldValue);
    var selectBox = document.getElementById(activeFloatingBox);
    currentInputKeyBox.value   = selectBox.value;
    currentInputValueBox.value = selectBox.options[selectBox.selectedIndex].text;
    hideFloatingCombo(activeFloatingCombo);
    currentInputValueBox.focus();
    if(postProcessFunctionName){
      try{
        eval(postProcessFunctionName + "(currentInputKeyBox.value,currentInputValueBox.value)");
        //doOnchangeFromPage(activeSelectedFieldValue);
      }catch(e){
        alert(e);
      }
    }
  }
}
